//
//  HHLazyGridSample.swift
//  HHSwiftuiPractice
//
//  Created by HongMac on 2023/10/3.
// 懒加载 网格视图 LazyGrid

import SwiftUI

struct HHLazyGridSample: View {
    var body: some View {
        let columns = [
            GridItem(.flexible()),
            GridItem(.flexible()),
            GridItem(.flexible())
        ]
        
        ScrollView{
            
            LazyVGrid(columns: columns, pinnedViews: [.sectionHeaders]) {
                Section {
                                    ForEach(0..<19) { index in
                                        Rectangle()
                                            .fill()
                                            .frame(height: 150)
                                    }
                                } header: {
                                    Text("Section 1")
                                        .font(.title)
                                        .foregroundColor(Color.white)
                                        .padding()
                                        .frame(maxWidth: .infinity, alignment: .leading)
                                        .background(Color.blue)
//                                        .padding()
                                }
                
                Section {
                                   ForEach(0..<49) { index in
                                       Rectangle()
                                           .fill(Color.purple)
                                           .frame(height: 150)
                                   }
                               } header: {
                                   Text("Section 2")
                                       .font(.title)
                                       .padding()
                                       .foregroundColor(Color.white)
                                       .frame(maxWidth: .infinity, alignment: .leading)
                                       .background(Color.orange)
                                      
                               }

            
            }
        }
        
        
    }
}

struct HHLazyGridSample_Previews: PreviewProvider {
    static var previews: some View {
        HHLazyGridSample()
    }
}
